package cn.tedu.kcircle.content.front.infra.repository.persist;

import cn.tedu.kcircle.common.po.PageData;
import cn.tedu.kcircle.common.util.TransPage;
import cn.tedu.kcircle.content.dao.entity.ContentDO;
import cn.tedu.kcircle.content.front.dao.mapper.ContentFrontMapper;
import cn.tedu.kcircle.content.front.infra.converter.ContentConverter;
import cn.tedu.kcircle.content.front.repository.model.ContentAddModel;
import cn.tedu.kcircle.content.front.repository.model.ContentListItemModel;
import cn.tedu.kcircle.content.front.repository.model.ContentStandardModel;
import cn.tedu.kcircle.content.front.repository.model.ContentUpdateModel;
import cn.tedu.kcircle.content.front.repository.persist.ContentRepository;
import cn.tedu.kcircle.content.front.service.bo.ContentListItemBO;
import cn.tedu.kcircle.content.front.service.bo.ContentStandardBO;
import com.github.pagehelper.PageHelper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@AllArgsConstructor
public class ContentRepositoryImpl implements ContentRepository {
    private ContentFrontMapper contentFrontMapper;
    private ContentConverter converter;
    @Override
    public Long insert(ContentAddModel contentAddModel) {
        ContentDO contentDO = converter.model2DO(contentAddModel);
        contentFrontMapper.insert(contentDO);
        return contentDO.getId();
    }

    @Override
    public int deleteById(Long id) {
        return contentFrontMapper.deleteById(id);
    }

    @Override
    public int updateById(ContentUpdateModel contentUpdateModel) {
        return contentFrontMapper.deleteById(contentUpdateModel);
    }

    @Override
    public ContentStandardModel getStandardById(Long id) {
        return contentFrontMapper.getStandardById(id);
    }

    @Override
    public PageData<ContentListItemModel> listPage(Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<ContentListItemModel> list=contentFrontMapper.list();
        PageHelper.clearPage();
        return TransPage.list2Page(list);
    }

    @Override
    public List<ContentStandardModel> listByAuthorId(Long authorId) {
        return contentFrontMapper.listByAuthorId(authorId);
    }

    @Override
    public Integer getResourceTypeById(Long id) {
        return contentFrontMapper.getResourceTypeById(id);
    }
}
